package design_pattern.WaitingRequestQueue;

import java.util.Random;

/**
 * @Author: 蔡翔
 * @Date: 2019/11/9 19:50
 * @Version 1.0
 */
public class ClientThread extends Thread {
    private final RequestQueue requestQueue;
    private final Random random;
    private final String sendValue;

    public ClientThread(RequestQueue requestQueue, String sendValue){
        this.requestQueue = requestQueue;
        this.sendValue = sendValue;
        random = new Random(System.currentTimeMillis());
    }


    @Override
    public void run() {
        for (int i = 0;i<10;i++){
            System.out.println("Client -> request" + sendValue);
            requestQueue.putRequest(new Request(sendValue));
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
